package algorithm.poj.p1000;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLDecoder;


/**
 * 分析：
 * 实现：
 * 经验：
 * 教训：
 * 
 * 
 * @author wong.tong@gmail.com
 *
 */
public class P1095 {

	public static void main(String[] args) throws Exception {

		InputStream input = null;
		if (false) {
			input = System.in;
		} else {
			URL url = P1095.class.getResource("P1095.txt");
			File file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
			input = new FileInputStream(file);
		}
		
		BufferedReader stdin = new BufferedReader(new InputStreamReader(input));

		String line = stdin.readLine();
		int T = Integer.valueOf(line.trim());
		for (int i = 0; i < T; i ++) {
			line = stdin.readLine();
			int N = Integer.valueOf(line.trim());
			int[] s = new int[N];
			int[] t = new int[N];
			for (int j = 0; j < N; j ++) {
				line = stdin.readLine();
				String[] tmp = line.split(" ");
				s[j] = Integer.valueOf(tmp[0].trim());
				t[j] = Integer.valueOf(tmp[1].trim());
			}
			System.out.println(moving(s, t)*10);
		}
	}
	
	private static int moving(int[] s, int[] t) {
		
		int max = 0;
		for (int i = 0; i < 200; i ++) {
			int count = 0;
			for (int j = 0; j< s.length; j ++) {
				//郁闷，这里地方可能s[j] <= t[j],也可能s[j] > t[j]
				if ((i >= (s[j]-1)/2 && i <= (t[j]-1)/2) || (i >= (t[j]-1)/2 && i <= (s[j]-1)/2)) {
					count ++;
				}
			}
			if (max < count) max= count;
		}
		return max;
	}
}